package com.appserver.web.controller;

import com.appserver.web.dto.UserModel;
import com.baidu.unbiz.easymapper.MapperFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 给内部系统访问的接口
 */
@RestController
@RequestMapping("/inner")
public class InnerOpenController {
    private static final Logger LOGGER = LoggerFactory.getLogger(InnerOpenController.class);

//    //包含接口
//    @Autowired
//    private IMUserApiService IMUserApiService;


//    //获取用户信息
//    @RequestMapping(path = "/user/{userId:\\d+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public Return<UserModel> getUser(@PathVariable(value = "userId") int userId
//                          ) {
//        UserModel userModel = MapperFactory.getCopyByRefMapper().mapClass(User.class, UserModel.class).register()
//                .map(IMUserApiService.getUserAndUpdate(userId, false), UserModel.class);
//
//        return new ReturnT<>(userModel);
//    }
//
//    //获取用户信息
//    @RequestMapping(path = "/users", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public ReturnT<List<UserModel>> getUsers(@RequestBody List<Integer> userIds
//    ) {
//        List<User> usersAndUpdate = IMUserApiService.getUsersAndUpdate(userIds, false);
//        MapperFactory.getCopyByRefMapper().mapClass(User.class, UserModel.class).register();
//        List<UserModel> userModels = usersAndUpdate.stream().map(p -> MapperFactory.getCopyByRefMapper().map(p,
//                UserModel.class)).collect(Collectors.toList());
//        return new ReturnT<>(userModels);
//    }
//
//    //获取用户最近的用户的基本信息
//    @RequestMapping(path = "/user/near/{userId:\\d+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public ReturnT<List<UserModel>> getUserNear(@PathVariable(value = "userId") int userId, @RequestParam(value = "distance", defaultValue = "1000") Integer distance
//    ) {
//        List<User> userNear = IMUserApiService.getUserNear(userId, distance);
//        List<UserModel> userNearModels = userNear.stream().map(p -> MapperFactory.getCopyByRefMapper().map(p,
//                UserModel.class)).collect(Collectors.toList());
//        return new ReturnT<>(userNearModels);
//    }
//    //鉴权
//    @RequestMapping(path = "/user/auth", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public ReturnT<UserModel> authUser(@RequestParam(value = "jwt", defaultValue = "") String jwt,
//                                  @RequestParam(value = "userId", defaultValue = "") int userId
//    ) {
//        User user = IMUserApiService.authUser(jwt, userId);
//        if(user == null){
//            return new ReturnT<>(ReturnT.FAIL_CODE, "jwt is not correct");
//        }
//        UserModel userModel = MapperFactory.getCopyByRefMapper().mapClass(User.class, UserModel.class).register()
//                .map(user, UserModel.class);
//        return new ReturnT<>(userModel);
//    }

}
